<template>
  <!-- 诉讼类型 -->
  <section class="component lwasuit-kind">
    <el-form :model="model" :rules="rules" ref="lwasuit-kind" label-width="90px">
      <el-form-item label="诉讼类型" prop="lwasuitKind">
        <el-radio-group v-model="model.lwasuitKind">
          <el-radio v-for="{index,name,code} in $dict.getDictData('LawsuitFollowType')" :key="index" :label="code">{{name}}</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div class="operate-buttons">
      <el-button @click="close">取消</el-button>
      <el-button @click="next">下一步</el-button>
    </div>

    <el-dialog title="诉讼跟进" center :visible.sync="dialog.isOpenLawsuitFollow" append-to-body width="900px" @open="() => this.$nextTick(() => this.$refs['lawsuit-follow'].refresh())" @close="close(), refreshData()">
      <lawsuit-follow ref="lawsuit-follow" @close="dialog.isOpenLawsuitFollow = false" @refreshData="refreshData" :lawsuit="lawsuit" :rowData="rowData"></lawsuit-follow>
    </el-dialog>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Dependencies } from "~/core/decorator";
import { Emit, Prop ,Watch} from "vue-property-decorator";
import { Getter } from "vuex-class";
import LawsuitFollow from "./lawsuit-follow.vue";
import { lawsuitStatus } from "./lawsuit.config";
import { OutsourceLawsuitService } from "~/services/domain-service/outsource-lawsuit-manage-index.service";

@Component({
  components: {
    LawsuitFollow
  }
})
export default class LawsuitKind extends Vue {
  @Dependencies(OutsourceLawsuitService)
  private outsourceLawsuitService: OutsourceLawsuitService

  @Prop()
  private rowData

  // 弹框控制
  private dialog: any = {
    isOpenLawsuitFollow: false
  }

  private model: any = {
    lwasuitKind: "LAWSUIT_RECORD"
  }

  private rules: any = {
    lwasuitKind: [{required: true, message: "请选择诉讼类型"}]
  }

  private get lawsuit() {
    return {
      kind: this.model.lwasuitKind,
      status: lawsuitStatus.court
    }
  }

  @Emit("refreshData")
  private refreshData() {}
  @Emit("close")
  private close() {}

  /**
   * 下一步
   */
  private next() {
    const form: any = this.$refs["lwasuit-kind"]
    form.validate((valid) => {
      if (!valid) return 
      const params = {caseAssistId: this.rowData.id, lawsuitFollowType: this.model.lwasuitKind,}
      this.outsourceLawsuitService.saveCourtInfo(params).subscribe(
        () => this.dialog.isOpenLawsuitFollow = true
      )
    })
  }

}
</script>

<style lang="less" scoped>

</style>
